import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Day1 {
    public static void main(String[] args) {
        StringBuilder str = new StringBuilder();
        str.append(1);
        str.append(2);
        str.append(3);
        System.out.println(str.toString());
        str.deleteCharAt(str.length()-1);
        System.out.println(str.toString());


    }
    public static void main1(String[] args) {
        int[] arr = {5,5,5,10,5,20,5,10,5,20};
        lemonadeChange(arr);
        Map<Character,String> map = new HashMap<>();
        List<String> ret = new ArrayList<>();

        String s = "a";
        ret.add(s);
    }
    //柠檬水找零
    public static boolean lemonadeChange(int[] bills) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int i=0;i<bills.length;i++) {
            if(bills[i] == 5) {
                map.put(5,map.getOrDefault(5,0)+1);
            }else if(bills[i] == 10){//给顾客找5元
                if(map.get(5) != null) {
                    map.put(5,map.get(5)-1);//5块钱零钱数量-1
                    map.put(10,map.getOrDefault(10,0)+1);  //10块钱数量+1
                }else {
                    return false;
                }
            }else {//顾客给20
                //1.先找10+5
                if(map.getOrDefault(5,0) >= 2 && map.getOrDefault(10,0) >= 1) {
                    map.put(5,map.get(5)-2);
                    map.put(10,map.get(10)-1);
                }else if(map.getOrDefault(5,0) >= 3) {//2.找5+5+5
                    map.put(5,map.get(5)-3);
                }else{//3.没有零钱
                    return false;
                }
            }
        }
        return true;
    }
    public boolean lemonadeChange2(int[] bills) {
        int m = 0;//5
        int n = 0;
        if(bills[0] >= 10) return false;//加一个条件可以多超越内存50的玩家
        for(int i=0;i<bills.length;i++) {
            if(bills[i] == 5) {
                m++;
            }else if(bills[i] == 10){//给顾客找5元
                if(m-- >= 1) {
                    n++;
                }else {
                    return false;
                }
            }else {//顾客给20
                //1.先找10+5
                if(m >= 1 && n >= 1) {
                    m--;
                    n--;
                }else if(m >= 3) {//2.找5+5+5
                    m-=3;
                }else{//3.没有零钱
                    return false;
                }
            }
        }
        return true;
    }
    //17.电话号码的字母组合
    List<String> ret = new ArrayList<>();
    StringBuilder path = new StringBuilder();
    Map<Character,String> map = new HashMap<>();
    public List<String> letterCombinations(String digits) {
        String ss = "";
        if(digits.equals("")) return ret;
        map.put('2',"abc");
        map.put('3',"def");
        map.put('4',"ghi");
        map.put('5',"jkl");
        map.put('6',"mno");
        map.put('7',"pqrs");
        map.put('8',"tuv");
        map.put('9',"wxyz");
        dfs(digits,0);
        return ret;
    }
    public void dfs(String s,int pos) {
        if(path.length() == s.length()) {
            ret.add(path.toString());
            return;
        }
        String strT = map.get(s.charAt(pos));//拿到2对应的字符串abc
        for(int i=0;i<strT.length();i++) {
            path.append(strT.charAt(i));
            dfs(s,pos+1);
            //回溯
            path.deleteCharAt(path.length()-1);
        }
    }



}
